//
// C++ Implementation: config
//
// Description:
//
//
// Author: Willi Ballenthin <wilbal1087@gmail.com>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "config.h"
#include <QDebug>
#include <QSqlQuery>
#include <QVariant>
#include <QStringList>
#include <QSqlError>

/**
 * Constructor.
 */
Config::Config()
{
    // doesnt do anything
}

/**
* Accessor to get database type.
* @return  A string containing the type of database to use.
*/
QString Config::getDBType()
{
    return type;
}

/**
* Opens a connection to an SQL database, based on the configuration
* provided by the configuration file.
* @return The SQL database connection or 0 on fail.
*/
QSqlDatabase* Config::getDB()
{
    if (! QString::compare ( type, "MYSQL", Qt::CaseInsensitive ) )
    {
        db = QSqlDatabase::addDatabase( "QMYSQL" );
        db.setHostName     ( host     );
        db.setDatabaseName ( database );
        db.setUserName     ( username );
        db.setPassword     ( password );
        if ( !db.open() )
        {
            qWarning ( "unable to open connection with database" );
            return 0;
        }

        db = QSqlDatabase::database();
        return &db;
    }

    qWarning ( "incompatible with database type suggested in the config file" );
    return 0;
}
